/**
 * Dashboard API 接口
 */
import { mockDashboardData } from '@/mock/dashboard'

// 是否使用 mock 数据
const USE_MOCK = true

/**
 * 获取仪表板数据
 * @returns {Promise}
 */
export const getDashboardData = () => {
  if (USE_MOCK) {
    // 使用 mock 数据
    return mockDashboardData()
  }

  // 实际 API 调用（当 USE_MOCK 为 false 时）
  // return request.postForm('/badp/dashboard/data')
}

/**
 * 获取用户信息
 * @returns {Promise}
 */
export const getUserInfo = () => {
  if (USE_MOCK) {
    return mockDashboardData().then(res => ({
      meta: res.meta,
      data: res.data.userInfo
    }))
  }
  // return request.postForm('/badp/dashboard/userinfo')
}

/**
 * 获取统计数据
 * @returns {Promise}
 */
export const getStatistics = () => {
  if (USE_MOCK) {
    return mockDashboardData().then(res => ({
      meta: res.meta,
      data: res.data.statistics
    }))
  }
  // return request.postForm('/badp/dashboard/statistics')
}

/**
 * 获取趋势数据
 * @param {Object} params - 查询参数
 * @returns {Promise}
 */
export const getTrendData = (params = {}) => {
  if (USE_MOCK) {
    return mockDashboardData().then(res => ({
      meta: res.meta,
      data: res.data.trendData
    }))
  }
  // return request.postForm('/badp/dashboard/trend', params)
}

/**
 * 获取服务排名
 * @returns {Promise}
 */
export const getServiceRanking = () => {
  if (USE_MOCK) {
    return mockDashboardData().then(res => ({
      meta: res.meta,
      data: res.data.serviceRanking
    }))
  }
  // return request.postForm('/badp/dashboard/service-ranking')
}

/**
 * 获取评价包服务排名
 * @returns {Promise}
 */
export const getPackageServiceRanking = () => {
  if (USE_MOCK) {
    return mockDashboardData().then(res => ({
      meta: res.meta,
      data: res.data.packageServiceRanking
    }))
  }
  // return request.postForm('/badp/dashboard/package-ranking')
}

/**
 * 获取地区排名
 * @param {String} type - 'top' 或 'bottom'
 * @returns {Promise}
 */
export const getRegionRanking = (type = 'top') => {
  if (USE_MOCK) {
    return mockDashboardData().then(res => ({
      meta: res.meta,
      data: type === 'top' ? res.data.topRegions : res.data.bottomRegions
    }))
  }
  // return request.postForm('/badp/dashboard/region-ranking', { type })
}
